package com.xyzh05.service.impl;

import java.util.List;

import javax.jws.WebService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xyzh05.dao.CommentDao;
import com.xyzh05.model.Comment;
import com.xyzh05.service.CommentManager;

@Service("commentManager")
@WebService(serviceName = "CommentService", endpointInterface = "com.xyzh05.service.CommentManager")
public class CommentManagerImpl extends GenericManagerImpl<Comment, Long> implements CommentManager {
    CommentDao commentDao;

    @Autowired
    public CommentManagerImpl(CommentDao commentDao) {
        super(commentDao);
        this.commentDao = commentDao;
    }

	public List<Comment> getAllByTime(Long owenId, Long owenType) {
		return commentDao.getAllByTime(owenId,owenType);
	}
	
	public List<Object[]> findStatistics(Long vipServiceId){
		StringBuilder findHql = new StringBuilder();
	/*	findHql.append(" select s.stBinary, count(s.stBinary), te.finished from TransactionEntry te ");
		findHql.append(" inner join te.service.serviceType s ");
		findHql.append(" left join te.vipServiceTransaction vipTe ");
		findHql.append(" where vipTe.vipService.id = ? ");
		findHql.append(" group by s.stBinary, te.finished "); */
		
		findHql.append(" select te.service.id, count(te.service.id), te.finished from TransactionEntry te "); 
		findHql.append(" left join te.vipServiceTransaction vipTe ");
		findHql.append(" where vipTe.vipService.id = ? ");
		findHql.append(" group by te.service.id, te.finished ");
		
		return (List<Object[]>) commentDao.findQuery(findHql.toString(), vipServiceId);		
	}

	public List<Comment> getTopNum(Integer vipServiceId, Integer minNum, Integer maxNum) {
		return commentDao.getTopNum(vipServiceId, minNum, maxNum);
	}
}